Add title tests about interwiki prefix
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 10 Jan 2014 20:40:25 +0000 (21:40 +0100)
committerUmherirrender <umherirrender_de.wp@web.de>
Tue, 4 Feb 2014 14:53:54 +0000 (14:53 +0000)
Also test $wgLocalInterwiki.
The js part does not respect interwikis,
so there is no need to add tests for that.

Change-Id: I407355295b65bc67eb171da435c1505797569d3e

tests/phpunit/includes/TitleTest.php

index 54e6199..078dfef 100644 (file)
@@ -40,6 +40,21 @@ class TitleTest extends MediaWikiTestCase {
         * @todo This method should be split into 2 separate tests each with a provider
         */
        public function testSecureAndSplit() {
+               $this->setMwGlobals( array(
+                       'wgLocalInterwiki' => 'localtestiw',
+                       'wgHooks' => array(
+                               'InterwikiLoadPrefix' => array(
+                                       function ( $prefix, &$data ) {
+                                               if ( $prefix === 'localtestiw' ) {
+                                                       $data = array( 'iw_url' => 'localtestiw' );
+                                               } elseif ( $prefix === 'remotetestiw' ) {
+                                                       $data = array( 'iw_url' => 'remotetestiw' );
+                                               }
+                                               return false;
+                                       }
+                               )
+                       )
+               ));
                // Valid
                foreach ( array(
                        'Sandbox',
@@ -58,7 +73,17 @@ class TitleTest extends MediaWikiTestCase {
                        'A~~',
                        // Length is 256 total, but only title part matters
                        'Category:' . str_repeat( 'x', 248 ),
-                       str_repeat( 'x', 252 )
+                       str_repeat( 'x', 252 ),
+                       // interwiki prefix
+                       'localtestiw: #anchor',
+                       'localtestiw:foo',
+                       'localtestiw: foo # anchor',
+                       'localtestiw: Talk: Sandbox # anchor',
+                       'remotetestiw:',
+                       'remotetestiw: Talk: # anchor',
+                       'remotetestiw: #bar',
+                       'remotetestiw: Talk:',
+                       'remotetestiw: Talk: Foo'
                ) as $text ) {
                        $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
                }
@@ -106,7 +131,11 @@ class TitleTest extends MediaWikiTestCase {
                        // Namespace prefix without actual title
                        'Talk:',
                        'Category: ',
-                       'Category: #bar'
+                       'Category: #bar',
+                       // interwiki prefix
+                       'localtestiw:',
+                       'localtestiw: Talk: # anchor',
+                       'localtestiw: Talk:'
                ) as $text ) {
                        $this->assertNull( Title::newFromText( $text ), "Invalid: $text" );
                }